#include <iostream>
#include <vector>
using namespace std;
#define int long long
struct SegTree {
    int n;
    vector<int> st;
    SegTree(const vector<int>& a) {
        n = a.size();
        st.assign(4 * n, 0);
        build(1, 0, n - 1, a);
    }
    // 建立对应的线段树结构
    void build(int p, int l, int r, const vector<int>& a) {
        if(l == r) {
            st[p] = a[l];
            return;
        }
        int mid = (l + r) >> 1;
        build(p << 1, l, mid, a);
        build(p << 1 | 1, mid + 1, r, a);
        st[p] = st[p << 1] + st[p << 1 | 1];
    }
    // 修改点的数值
    void point_update(int idx, int val) {
        point_update(1, 0, n - 1, idx, val);
    } 
    void point_update(int p, int l, int r, int idx, int val) {
        if(l == r) {
            st[p] = val;
            return;
        }
        int mid = (l + r) >> 1;
        if(idx <= mid) {
            point_update(p << 1, l, mid, idx, val);
        }else {
            point_update(p << 1 | 1, mid + 1, r, idx, val);
        }
        st[p] = st[p << 1] + st[p << 1 | 1];
    }
    // 查询区间
    int range_query(int l, int r) {
        return range_query(1, 0, n - 1, l, r);
    }
    int range_query(int p, int l, int r, int L, int R) {
        if(R < l || L > r) {
            return 0;
        }
        if(L <= l && r <= R) {
            return st[p];
        }
        int mid = (l + r) >> 1;
        return range_query(p << 1, l, mid, L, R) + range_query(p << 1 | 1, mid + 1, r, L, R);
    }
};
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> a = {1, 2, 3, 4, 5};
    SegTree seg(a);
    cout << seg.range_query(1, 3) << "\n"; // sum of a[1..3] = 2+3+4 = 9
    seg.point_update(2, 10);               // a[2] = 10
    cout << seg.range_query(1, 3) << "\n"; // 2+10+4 = 16
    return 0;
}